//
//  AppDelegate.swift
//  WeiBo_NB
//
//  Created by apple on 15/3/2.
//  Copyright (c) 2015年 Ai. All rights reserved.
//

import UIKit

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?
    

    func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
        // 设置导航条颜色
        var appear = UINavigationBar.appearance()
        appear.tintColor = UIColor.orangeColor()
        
        if let token = AccessToken.loadAccessToken(){
            // 已经登录过，读取上次的登录信息
            println(token.debugDescription)
//            println(token.uid)
            
            changeViewController()
           
        }else{
            NSNotificationCenter.defaultCenter().addObserver(self, selector: "changeViewController", name: WB_Login_Notefication, object: nil)
        }
        
        
        let em = EmoticonsSection.loadEmoticons()
        
    
        
//         let net = SampleNeworks()
//        println(net.cacheImageUrl)
//        var url = "http://pic.chinadaily.com.cn/img/attachement/jpg/site1/20150310/00221917eae81668aa192c.jpg"
//        var urls = ["http://images.china.cn/attachement/jpg/site1000/20150310/7427ea210c5416686dc344.jpg",
//            "http://img1.gtimg.com/12/1201/120188/12018841_980x1200_0.jpg",
//            "http://img1.gtimg.com/12/1201/120188/12018840_980x1200_0.jpg"]
//        net.downloadImages(urls, completion: { (result, error) -> () in
//            println("All-OK")
//        })
//        net.downloadImage(url, completion: { (result, error) -> () in
//            println("OK")
//        })
        return true
    }
    
///  切换控制器
    func changeViewController(){
        // 移除监听
        NSNotificationCenter.defaultCenter().removeObserver(self)
        // 切换控制器
        let sb = UIStoryboard(name: "Main", bundle: nil)
        let vc = sb.instantiateInitialViewController() as! UIViewController
        window?.rootViewController = vc
    }

 


}

